<div class="layuimini-main">
	<div class="layui-form layuimini-form" lay-filter="form-data">
		<div class="layui-form-item">
			<label class="layui-form-label required">父级菜单名称</label>
			<div class="layui-input-block">
				<input type="text" name="parentName" lay-verify="required" lay-reqtext="父级菜单名称不能为空" placeholder="请输入父级菜单名称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">菜单名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" lay-verify="required" lay-reqtext="菜单名称不能为空" placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">链接地址</label>
			<div class="layui-input-block">
				<input type="text" name="url" lay-verify="required" lay-reqtext="链接地址不能为空" placeholder="如：http://512.team" autocomplete="off" class="layui-input">
			</div>
		</div>
		<input type="hidden" name="id"/>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
			</div>
		</div>
	</div>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
			parentIndex = layer.index,
			parentData = JSON.parse(parent.data);
		
		//给表单赋值
		form.val("form-data", {
		  "parentName": parentData.parentName
		  ,"name": parentData.name
		  ,"url": parentData.url
		  ,"id": parentData.id
		});

        form.on('submit(saveBtn)', function(data) {
			$.ajax({
				url: '/globalConfig/customizedMenu/update',
				type: 'POST',
				dataType: "json",
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(data.field),
				success: function(data){
					if(data.code != "000000"){
						layer.msg(data.message, {icon: 5, shift: 6});
						return false;
					}
					layer.close(parentIndex);
					layer.msg("保存成功", {
						icon: 1,
						time: 500,
						shade: 0.01,
						shadeClose: false}, function(){
						window.location = '/index.html';
					});
				},
				error: function(data){
					layer.close(parentIndex);
					layer.msg(data.message, {icon: 5, shift: 6});
				}
			});
            return false;
        });
    });
</script>